import java.util.Map;

/**
 *
 * @author jillsanluis
 */
public class ReadingThread extends Thread{

    private Map<Integer, PeerInfo> peerPool;

    public ReadingThread(Map<Integer, PeerInfo> peerPool){
        this.peerPool = peerPool;
    }

    @Override
    public void run(){

        while(true){
            try{
                Thread.sleep(1);
            }
            catch(InterruptedException ie){
                // do nothing
            }

            // process the packet

            Packet p= PacketOrderedQueue.getInstance().pop();

            if(p!=null){

                PeerInfo pInfo = peerPool.get(p.getPeerID());
                if(pInfo != null){
                    p.getAction().act(pInfo.getClient());
                }

            }
        }
    }

}
